package com.mitdy.sg.data.crawler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.downloader.selenium.SeleniumDownloader;
import us.codecraft.webmagic.scheduler.QueueScheduler;

@Component
public class SportGameCrawler {

    @Value("${system.config.chromeDriverPath}")
    private String chromeDriverPath;

    @Autowired
    private BasketballPageProcessor basketballPageProcessor;

    public void start(int index) {
        basketballPageProcessor.setIndex(index);
        Spider.create(basketballPageProcessor).thread(1).addUrl(basketballPageProcessor.getUrl())
                .setScheduler(new QueueScheduler()).setDownloader(new SeleniumDownloader(chromeDriverPath)).run();
    }

}
